<?php
require_once dirname(__FILE__) . '/includes/common.inc.php';
require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';

//header('Content-Type: text/plain');

/*if (isset($_COOKIE[OPERATOR])) { 
 $coperator = json_decode($_COOKIE[OPERATOR]);
}
*/
//echo str_replace("world","<span style=\"background-color:#FF0\">John</span>","Hello world!");

try {
  $oid = MiscUtils::getParam('id', 880);
  
  /*$u = MiscUtils::getParam('u', json_encode(array()));
  $u = json_decode(urldecode($u));
  $user=isset($u->user)? $u->user : '';
  $pass=isset($u->pass)? $u->pass : '';  */
  
  //$options = new stdClass();
  //$options->name = array('Rochelle Thrupp');
  //$options->venue = array('13901 Central Avenue','Angel oresanz','Angelinas Restaurant','Unknow');
  //$options->contact = array('5227289');
  //$options->wd = array('2009-02-14','2010-03-19');
  
   $result = new stdClass();
   //$result->data1 = array();
  // $tmp = new stdClass();
   $result->data = array();
   $tmpaf = array();

   if(!empty($oid))
   {
   	  $sql = "select * from ns_v1customer where e_oid =".$oid." ";
   	  
   	  $cusinfo = getone($sql);
   	  
   	  //$tmpaf = $cusinfo;
   	  
   	  $tmpaforders = array();
   	  
   	  $tmporder = getsonall('ns_v1myorder','customerId',$cusinfo->e_oid);
   	  
   	  //$tmpaf->orders = $tmporder;
   	  
   	  foreach($tmporder as $order)
   	  {
   	      $order->products = array();
          $pitem = getsonall('ns_v1purchaseitem','order_id',$order->e_oid);
          $order->products = $pitem;
          
          
          $order->payments = array();
          $payment = getsonall('ns_v1payment','orderId',$order->e_oid); 
          $order->payments = $payment;

          $order->produce = array();
          /*这里显示流程*/

          $tmpaforders[] = $order;
   	  }
   	  
   	  //print_r($tmpaforders);
   	  //$result->data = $cusinfo;
   	  
   	  /*foreach($cusinfo as $cusone)
   	  {
   	  	$result->data [] = $cusone;
   	  }*/
   	  
   	  $tmpaf['bridename'] = $cusinfo->bridename;
   	  $tmpaf['bridephone'] = $cusinfo->bridephone;
   	  $tmpaf['bridemobile'] = $cusinfo->bridemobile;
   	  $tmpaf['brideemail'] = $cusinfo->brideemail;
   	  $tmpaf['brideaddrLn1'] = $cusinfo->brideaddrLn1;
   	  $tmpaf['brideaddrLn2'] = $cusinfo->brideaddrLn2;
   	  $tmpaf['brideaddrLn3'] = $cusinfo->brideaddrLn3;
   	  $tmpaf['brideaddrLn4'] = $cusinfo->brideaddrLn4;
   	  
   	  $tmpaf['groomname'] = $cusinfo->groomname;
   	  $tmpaf['groomphone'] = $cusinfo->groomphone;
   	  $tmpaf['groommobile'] = $cusinfo->groommobile;
   	  $tmpaf['groomemail'] = $cusinfo->groomemail;
   	  $tmpaf['groomaddrLn1'] = $cusinfo->groomaddrLn1;
   	  $tmpaf['groomaddrLn2'] = $cusinfo->groomaddrLn2;
   	  $tmpaf['groomaddrLn3'] = $cusinfo->groomaddrLn3;
   	  $tmpaf['groomaddrLn4'] = $cusinfo->groomaddrLn4;
   	  
   	  $tmpaf['orders'] = $tmpaforders;
   	  
   	  
   	 // print_r($result->data);
   	  
   } 
   $result->data[] =  $tmpaf;
  
  

  
  echo json_encode($result);

} catch (PDOException $e) {
  echo $e->getMessage();
}

function arrayucwords($str)
{
	if(is_array($str))
	{
		$tmp = array();
		foreach($str as $onearr)
		{
			$tmp[] = ucwords($onearr);
		}
		return $tmp;
	}else{
		return ucwords($str);
	}
	
}


function strtoarray($str)
{
	$namearr1 = array();
               $narr1 = split (' ', $str);
                
                foreach ($narr1 as $na1)
                {
                    $val1 = trim($na1);
                    if( !empty( $val1 ) )
                    {
                       $namearr1[] = $na1;
                    }
                }

                return $namearr1;
}

/**
 * $str 需要高亮显示的字符串,
 * $keyword 关键字  可以为数组,
 * $issplit=''  是否把当个关键字按照空格拆开成多个关键字
 */
function keywordlight($str,$keyword,$issplit='')
{
	if(is_array($keyword))
	{
		foreach($keyword as $onekw)
		{
			if(!empty($issplit))
			{
				$splitarr = strtoarray($onekw);
				 
				foreach($splitarr as $onesp)
				{
					$str = str_replace($onesp,"<span style=\"background-color:#FF0\">".$onesp."</span>",$str);
				}
				
			}else{
		        $str = str_replace($onekw,"<span style=\"background-color:#FF0\">".$onekw."</span>",$str);
			}
		}
	}else{
		$str = str_replace($keyword,"<span style=\"background-color:#FF0\">".$keyword."</span>",$str);
	}
	
	return $str;
}

?>